//
//  ResultModel.swift
//  LongTermInsurance
//
//  Created by zolobdz on 2018/12/22.
//  Copyright © 2018年 HeChao. All rights reserved.
//

import UIKit
import ObjectMapper

class JudgeResult: NSObject, Mappable {
    
    var applyNum: Int = 0
    var applyDate = ""
    var mobile = ""
    var address = ""
    var helperName = ""
    var helperMobile = ""
    var judgeDate = ""
    var judgeResult = ""
    
//    [{\"APPLYNO\":2546.0,\"APPLYDATE\":\"2017-10-28T10:23:12\",\"MOBILENO\":\"13402504299\",\"ADDRESS\":\"苏州心圆护理院东兴路199号（十二病区1251床）\",\"GUANAME\":\"吴勋军\",\"GUAMIBILENO\":\"13402504299\",\"GUAADDRESS\":null,\"ASSESSDATE\":\"2017-11-21T16:27:30\",\"ASSESSRESULT\":\"轻度失能\"}]
    required init?(map: Map) {
        
    }
    
    func mapping(map: Map) {
        applyNum <- map["APPLYNO"]
        applyDate <- map["APPLYDATE"]
        mobile <- map["MOBILENO"]
        address <- map["ADDRESS"]
        helperName <- map["GUANAME"]
        helperMobile <- map["GUAMIBILENO"]
        judgeDate <- map["ASSESSDATE"]
        judgeResult <- map["ASSESSRESULT"]
        if applyNum == 0 {
            applyNum <- map["ApplyNo"]
            applyDate <- map["ApplyDate"]
            mobile <- map["MobileNo"]
            address <- map["Address"]
            helperName <- map["GuaName"]
            helperMobile <- map["GuaMibileNo"]
            judgeDate <- map["AssessDate"]
            judgeResult <- map["AssessResult"]
        }
    }

}

class MyApplyModel: NSObject, Mappable {
    var showDetail = false
    var cellHeight: Float {
        return showDetail ? 340.0 : 220
    }
    var canModify: Bool {
        if showDetail && detailModel != nil{
            if detailModel.trialState.contains("退回") {
                return true
            }
        }
        return false
    }
    
    var applyNO = 0
    var applyDate = ""
    var mobileNO = ""
    var address = ""
    var carePeople = ""
    var carePeopleMobile = ""
    var carePeopleAddress = ""
    var auditStatus = ""
    
    var detailModel: MyApplyDetailModel!
    //    \"APPLYNO\":申请单号,\"APPLYDATE\":\"申请时间\",\"MOBILENO\":\"移动电话\",\"ADDRESS\":\"住址\",\"GUANAME\":\"监护人\",\"GUAMIBILENO\":\"监护人电话\",\"GUAADDRESS\":\"监护人地址\",\"AUDITSTATUS\":\"审核状态\"
    required init?(map: Map) {
        
    }
    
    func mapping(map: Map) {
        applyNO <- map["APPLYNO"]
        applyDate <- map["APPLYDATE"]
        mobileNO <- map["MOBILENO"]
        address <- map["ADDRESS"]
        carePeople <- map["GUANAME"]
        carePeopleMobile <- map["GUAMIBILENO"]
        carePeopleAddress <- map["GUAADDRESS"]
        auditStatus <- map["AUDITSTATUS"]
        
        if applyNO == 0 {
            applyNO <- map["ApplyNo"]
            applyDate <- map["ApplyDate"]
            mobileNO <- map["MobileNo"]
            address <- map["Address"]
            carePeople <- map["GuaName"]
            carePeopleMobile <- map["GuaMibileNo"]
            carePeopleAddress <- map["GuaAddress"]
            auditStatus <- map["AuditStatus"]
        }
    }
    
    func getDetailRequest(complete: @escaping ()->(Void)) {
        let json = ["ApplyNum": applyNO].convertToJsonString()
        var paramString = "<CodeName>applyprogress</CodeName>"
        paramString += "<json>"+json+"</json>"
//        fetchNetworkData
        NetworkingHandle.oldfetchNetworkData(method: "ExeHNService", paramString: paramString, success: {[weak self] (dict) in
            
            
            if let code = dict["Code"] as? Int,code == 0 {
                if let array = dict["Message"] as? [Any],let data = array.first as? Dictionary<String, Any> {
                    if let model = Mapper<MyApplyDetailModel>().map(JSON: data) {
                        self?.detailModel = model
                        complete()
                    }
                }
                return
            }
            if let code = dict["Code"] as? Int,code == 1 {
                if let msgString = dict["Message"] as? String {
                    CDUtility.showMSG(message: msgString)
                }
            }
        }) {
            print("")
        }
    }
    
}



class MyApplyDetailModel: NSObject, Mappable {
    var applyNO = 0
    var applyDate = ""
    var auditDate = ""
    var reviewDate = ""
    var publicityDate = ""
    var conclusionDate = ""
    var trialState = ""
    var trialDate = ""
    var assessState = ""
    var reviewState = ""
    var publicityState = ""
    var conclusionState = ""
//    {"ApplyNum":"申请单号","ApplyDate":"申请日期","AssessDate":"评估日期","ReviewDate":"复核日期","PublicityDate":"公示日期","ConclusionDate":"结论时间","TrialState":"申请审核状态","TrialDate":"商保审核时间","AssessState":"评估状态","ReviewState":"复核状态","PublicityState":"公示状态","ConclusionState":"结论状态"}
    required init?(map: Map) {
        
    }
    
    func mapping(map: Map) {
        applyNO <- map["ApplyNum"]
        applyDate <- map["ApplyDate"]
        
        auditDate <- map["AssessDate"]
        reviewDate <- map["ReviewDate"]
        publicityDate <- map["PublicityDate"]
        conclusionDate <- map["ConclusionDate"]
        trialState <- map["TrialState"]
        trialDate <- map["TrialDate"]
        assessState <- map["AssessState"]
        reviewState <- map["ReviewState"]
        publicityState <- map["PublicityState"]
        conclusionState <- map["ConclusionState"]
//        if applyNO == 0 {
//            applyNO <- map["ApplyNo"]
//            applyDate <- map["ApplyDate"]
//            mobileNO <- map["MobileNo"]
//            address <- map["Address"]
//            carePeople <- map["GuaName"]
//            carePeopleMobile <- map["GuaMibileNo"]
//            carePeopleAddress <- map["GuaAddress"]
//            auditStatus <- map["AuditStatus"]
//        }
    }
    
}
